﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/MainTemplate.Master" AutoEventWireup="true" CodeBehind="Pages.aspx.cs" Inherits="Enterprise.Admin.Pages" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <script src="../Content/Widget/kindeditor/kindeditor-min.js" type="text/javascript" charset="utf-8"> </script>
    <script src="../Content/Widget/kindeditor/lang/zh_CN.js" type="text/javascript" charset="utf-8"> </script>
    <script src="../Content/Widget/kindeditor/plugins/code/prettify.js" type="text/javascript" charset="utf-8"> </script>
    <link href="../Content/Widget/kindeditor/plugins/code/prettify.css" rel="stylesheet" />
    <script src="../Content/Widget/jquery.json.min.js" type="text/javascript" charset="utf-8"> </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <table id="table_list"></table>
    <div id="search_page">
        <form id="search_page_form" action="Handle/GetColumnListJson.aspx" method="get">
            <p>
                <label>栏目：</label><input id="search_column_id" name="CoColumnId" />
            </p>
            <p>
                <label>页面标题：</label><input type="text" name="CoTitle" />
            </p>
            <p class="multi-language">
                <label>语言：</label><select name="CoLanguage" class="easyui-combobox">
                    <option value="">全部</option>
                    <option value="zh_cn">简体中文</option>
                    <option value="en_us">美国英语</option>
                </select>
            </p>
        </form>
    </div>
    <div id="add_page">
        <form id="add_page_form" action="Handle/AddPages.aspx" method="post">
            <div id="add_page_tabs" style="height: auto; padding: 0px;">
                <div title="基础资料">
                    <p>
                        <label>栏目：</label><input id="add_column_id" name="CoColumnId" />
                    </p>
                    <p>
                        <label>名称：</label><input name="CoKeyName" />
                    </p>

                    <p>
                        <label>页面标题：</label><input type="text" name="CoTitle" />
                    </p>
                    <p>
                        <label>作者：</label><input type="text" name="CoAuthor" value="" />
                    </p>
                    <p>
                        <label>关键字：</label><input type="text" name="CoKeyWord" value="" />
                    </p>

                    <p>
                        <label style="height: 70px; line-height: 70px;">描述：</label><textarea cols="" rows="" style="height: 60px; width: 300px;" name="CoDescription"></textarea>
                    </p>
                    <p>
                        <label>创建日期：</label><input type="text" name="CoDate" value="<%=DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") %>" class="easyui-datetimebox" />
                    </p>
                    <p class="multi-language">
                        <label>语言：</label><select name="CoLanguage" class="easyui-combobox" data-options="required:true">
                            <option value="zh_cn">简体中文</option>
                            <option value="en_us">美国英语</option>
                        </select>
                    </p>
                    <p>
                        <label>是否推荐：</label><input type="checkbox" name="CoIsRecommend" value="true" />

                    </p>
                </div>
                <div title="页面内容" style="height: 100%">
                    <textarea rows="" cols="" name="CoContent" id="add_page_content"></textarea>
                </div>
            </div>
        </form>
    </div>
    <div id="edit_page">
        <form id="edit_page_form" action="Handle/EditPages.aspx" method="post">
            <div id="edit_page_tabs" style="height: auto; padding: 0px;">
                <div title="基础资料">
                    <p>
                        <label>栏目：</label><input id="edit_column_id" name="CoColumnId" />
                        <input id="edit_page_id" name="CoPageId" type="hidden" value="" />
                    </p>
                    <p>
                        <label>名称：</label><input name="CoKeyName" />
                    </p>
                    <p>
                        <label>页面标题：</label><input type="text" name="CoTitle" value="" />
                    </p>
                    <p>
                        <label>作者：</label><input type="text" name="CoAuthor" value="" />
                    </p>
                    <p>
                        <label>关键字：</label><input type="text" name="CoKeyWord" value="" />
                    </p>
                    <p>
                        <label style="height: 70px; line-height: 70px;">描述：</label><textarea style="height: 60px; width: 300px;" name="CoDescription"></textarea>
                    </p>
                    <p>
                        <label>创建日期：</label><input type="text" id="edit_date" name="CoDate" value="" class="easyui-datetimebox" />
                    </p>

                    <p>
                        <label>语言：</label><select name="CoLanguage" class="easyui-combobox" data-options="required:true">
                            <option value="zh_cn">简体中文</option>
                            <option value="en_us">美国英语</option>
                        </select>
                    </p>
                    <p>
                        <label>是否推荐：</label><input type="checkbox" name="CoIsRecommend" value="true" />

                    </p>
                </div>
                <div title="页面内容" style="height: 100%">
                    <textarea name="CoContent" id="edit_page_content"></textarea>
                </div>
            </div>
        </form>
    </div>

    <script type="text/javascript">
        $(document).ready(function () {
            var tableList = $("#table_list").datagrid({
                title: '页面列表',
                fit: true,
                nowrap: true,
                autoRowHeight: false,
                striped: true,
                collapsible: true,
                fitColumns: true,
                url: 'Handle/GetPagesListJson.aspx',
                idField: 'id',
                singleSelect: true,
                onClickRow: function (rowIndex) {
                    $('#table_list').datagrid("unselectRow", rowIndex);
                },
                columns: [[
                    { title: 'Id', field: 'id', width: 280, align: 'center', checkbox: true },
                    { title: '名称', field: 'CoKeyName', width: 280, align: 'center' },
                    { title: '页面标题', field: 'CoTitle', width: 280, align: 'center' },
                    { title: '创建日期', field: 'CoDate', width: 180, align: 'center' },
                    { title: '栏目', field: 'CoColumnName', width: 100, align: 'center' },
                    {
                        title: '语言',
                        field: 'CoLanguage',
                        width: 100,
                        align: 'center',
                        formatter: function (value) {
                            var text;
                            $.each(languageData, function () {
                                if (this.id == value) {
                                    text = this.text;
                                    return false;
                                }
                                return true;
                            });
                            return text;
                        }
                    },
                    {
                        field: 'CoIsRecommend',
                        title: '推荐',
                        width: 60,
                        align: 'center',
                        formatter: function (value) {
                            return value ? '是' : '否';
                        }
                    },
                    {
                        title: '修改',
                        field: 'OpEdit',
                        width: 80,
                        align: 'center',
                        formatter: function (value, rec) {
                            return '<a href="javascript:void(0);" mce_href="#" onclick="edit(\'' + rec.id + '\')">修改</a> ';
                        }
                    },
                   {
                       title: '生成',
                       field: 'OpGenerate',
                       width: 80,
                       align: 'center',
                       formatter: function (value, rec) {
                           return '<a href="javascript:void(0);" mce_href="#" onclick="generate(\'' + rec.id + '\')">生成</a> ';
                       }
                   },
                    {
                        title: '删除',
                        field: 'OpDelete',
                        width: 80,
                        align: 'center',
                        formatter: function (value, rec) {
                            return '<a href="javascript:void(0);" mce_href="#" onclick="del(\'' + rec.id + '\')">删除</a> ';
                        }
                    }
                ]],
                pagination: true,
                rownumbers: true,
                toolbar: [{
                    text: '添加',
                    iconCls: 'icon-add',
                    handler: function () {
                        add();
                    }
                }, {
                    text: '修改',
                    iconCls: 'icon-edit',
                    handler: function () {
                        var selectData = $('#table_list').datagrid('getSelected');
                        if (selectData == null) {
                            $.messager.show({
                                title: '提示',
                                msg: '请选择要修改记录！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        } else {
                            edit(selectData.id);
                        }
                    }
                }, {
                    text: '删除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        var selectData = $('#table_list').datagrid('getSelected');
                        if (selectData == null) {
                            $.messager.show({
                                title: '提示',
                                msg: '请选择要删除记录！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        } else {
                            del(selectData.id);
                        }

                    }
                }, {
                    text: '查找',
                    iconCls: 'icon-search',
                    handler: function () {
                        $('#search_page').dialog("open");
                    }
                }]
            });
            $('#add_page').dialog({
                title: '添加页面',
                width: 750,
                height: 500,
                closed: true,
                buttons: [{
                    text: '保存',
                    iconCls: 'icon-ok',
                    handler: function () {
                        addPageContent.sync();
                        addSave(function () {
                        });
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#add_page').dialog('close');
                    }
                }]
            });
            $('#edit_page').dialog({
                title: '修改页面',
                width: 750,
                height: 500,
                closed: true,
                buttons: [{
                    text: '保存',
                    iconCls: 'icon-ok',
                    handler: function () {
                        editPageDescription.sync();
                        editSave();
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#edit_page').dialog('close');
                    }
                }]
            });
            $('#search_page').dialog({
                title: '检索页面',

                width: 400,
                height: 250,
                closed: true,
                buttons: [{
                    text: '查找',
                    iconCls: 'icon-ok',
                    handler: function () {
                        tableList.datagrid("reload", $('#search_page_form').serializeObject());
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#search_page').dialog('close');
                    }
                }]
            });
            $('#edit_page_form').form({
                onBeforeLoad: function () {
                },
                onLoadSuccess: function (data) {
                    editPageDescription.html(data.CoContent);

                    $('#edit_date').datetimebox('setValue', data.CoDate);
                    $('#edit_page').dialog("open");
                },
                onLoadError: function () {
                }
            });
            $('#add_page_tabs').tabs({
                border: false
            });
            $('#edit_page_tabs').tabs({
                border: false
            });
            var addPageContent = window.KindEditor.create('#add_page_content', {
                uploadJson: "Handle/KindEditorUploadJson.aspx",
                fileManagerJson: "Handle/KindEditorFileManagerJson.aspx",
                width: '668px',
                height: '375px',
                filterMode: false,
                allowFileManager: true,
                afterCreate: function () {

                }
            });
            var editPageDescription = window.KindEditor.create('#edit_page_content', {
                uploadJson: "Handle/KindEditorUploadJson.aspx",
                fileManagerJson: "Handle/KindEditorFileManagerJson.aspx",
                width: '668px',
                height: '375px',
                filterMode: false,
                allowFileManager: true,
                afterCreate: function () {

                }
            });
            $.ajax({
                type: "POST",
                url: "Handle/GetColumnTreeDataJson.aspx",
                success: function (data) {
                    var searchData = data.concat();
                    $('#add_column_id').combotree({
                        data: data
                    });
                    $('#edit_column_id').combotree({
                        data: data
                    });
                    searchData.unshift({ id: '', text: '全部' });
                    $('#search_column_id').combotree({
                        data: searchData
                    });
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '删除失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });

        });
        //获取页面详细
        function edit(id) {
            $('#edit_page_form').form('load', 'Handle/GetPagesDetailJson.aspx?id=' + id);
        }
        function del(id) {
            $.messager.confirm("提示", "确认删除?", function (b) {
                if (b) {
                    $.ajax({
                        type: "POST",
                        url: "Handle/DeletePages.aspx",
                        data: { id: id },
                        success: function (msg) {
                            $.messager.show({
                                title: '提示',
                                msg: msg.message,
                                timeout: 5000,
                                showType: 'fade'
                            });
                            if (msg.state)
                                $("#table_list").datagrid("reload");
                        },
                        error: function () {
                            $.messager.show({
                                title: '提示',
                                msg: '删除失败！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        }
                    });
                }

            });

        }
        function add() {
            $('#add_page').dialog("open");
        }
        //添加保存
        function addSave() {
            $.ajax({
                type: "POST",
                url: "Handle/AddPages.aspx",
                data: $('#add_page_form').serialize(),
                success: function (msg) {
                    $.messager.show({
                        title: '提示',
                        msg: msg.message,
                        timeout: 5000,
                        showType: 'fade'
                    });
                    if (msg.state) {
                        $("#table_list").datagrid("reload");
                        $('#add_page_form')[0].reset();
                    }
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '保存失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });
        }

        //编辑保存
        function editSave() {
            $.ajax({
                type: "POST",
                url: "Handle/EditPages.aspx",
                data: $('#edit_page_form').serialize(),
                success: function (msg) {
                    $.messager.show({
                        title: '提示',
                        msg: msg.message,
                        timeout: 5000,
                        showType: 'fade'
                    });
                    if (msg.state)
                        $("#table_list").datagrid("reload");
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '保存失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });
        }
        //生成
        function generate(id) {
            $.ajax({
                type: "POST",
                url: "Handle/Page/Generate.aspx",
                data: { id: id },
                success: function (msg) {
                    $.messager.show({
                        title: '提示',
                        msg: msg.message,
                        timeout: 5000,
                        showType: 'fade'
                    });
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '生成失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });
        }
    </script>
</asp:Content>
